# Maintainer: <waruqi@gmail.com>

_realname=xmake
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=2.9.9
pkgrel=1
pkgdesc="A cross-platform build utility based on Lua (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64')
msys2_references=(
  'archlinux: xmake'
)
msys2_repository_url='https://github.com/xmake-io/xmake/'
url='https://xmake.io/'
license=('spdx:Apache-2.0')
depends=("${MINGW_PACKAGE_PREFIX}-ncurses"
         "${MINGW_PACKAGE_PREFIX}-readline")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc")
source=("https://github.com/xmake-io/${_realname}/releases/download/v${pkgver}/${_realname}-v${pkgver}.tar.gz")
sha256sums=('e92505b83bc9776286eae719d58bcea7ff2577afe12cb5ccb279c81e7dbc702d')

prepare() {
    # Workaround: tarception
    tar -xf "${_realname}-v${pkgver}.tar"
}

build() {
    cd "${_realname}-${pkgver}"

    if [[ ${CARCH} == aarch64 ]]; then
        export CFLAGS+=" -D_M_ARM64"
    fi

    ./configure --prefix="${MINGW_PREFIX}" --toolchain=${CC}
    make
}

package() {
    cd "${_realname}-${pkgver}"
    make install PREFIX="${pkgdir}${MINGW_PREFIX}"
    install -Dm644 "LICENSE.md" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE.md"
}
